package wms.service.store;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import wms.dao.store.StoreSetMapper;
import wms.entity.StoreSet;

@Service
public class StoreSetServiceImpl implements StoreSetService{
	
	@Autowired
	private StoreSetMapper storeSetMapper;
	
	@Override
	public boolean deleteStoreSet(String goodsCode, String repoCode) throws Exception {
		if (goodsCode == null && repoCode == null) {
			throw new RuntimeException("没有该物资的库存信息!");
		}

		return storeSetMapper.txDeleteStoreSet(goodsCode, repoCode);
	}

	@Override
	public boolean saveStoreSet(StoreSet storeSet) throws Exception {
		//如果已经存在,那么修改库存
		//不存在则添加
		StoreSet dbStoreSet = getStoreSet(storeSet.getGoodsCode(), storeSet.getRepoCode());
		if (dbStoreSet != null) {
			dbStoreSet.setStoreNum(storeSet.getStoreNum());
			return modifyStoreSet(dbStoreSet);
		}
		return storeSetMapper.txSave(storeSet);
	}

	@Override
	public boolean modifyStoreSet(StoreSet storeSet) throws Exception {
		return storeSetMapper.txModify(storeSet);
	}

	@Override
	public List<StoreSet> listAllStoreSet(String goodsCode, String goodsName, Integer goodsType, String repoCode,
			Date startDate, Date endDate, Integer startPage, Integer pageSize) throws Exception {
		return storeSetMapper.listAllStoreSet(goodsCode, goodsName, goodsType, repoCode, startDate, endDate, startPage, pageSize);
	}

	@Override
	public StoreSet getStoreSet(String goodsCode, String repoCode) throws Exception {
		return storeSetMapper.getStoreSet(goodsCode, repoCode);
	}

	@Override
	public int getTotalCount(String goodsCode, String goodsName, Integer goodsType, String repoCode, Date startDate,
			Date endDate) throws Exception {
		return storeSetMapper.getTotalCount(goodsCode, goodsName, goodsType, repoCode, startDate, endDate);
	}

}
